

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="hz">
  <meta name="keywords" content="">
  
    <meta name="description" content="众所周知，flutter是比较流行的跨平台方案，目前可以构建出Android，iOS，macOS，Windows，web等产物，这里只想介绍一下Android和iOS的构建产物方式，理解了这两种产物的构建，自动动手实现其他产物，应该并不是什么难事。  首先，要构建出release包，也就是用户可以安装的包，无论是在Android，还是iOS上，都是需要”证书“来签名的。两个平台对比了解如下：">
<meta property="og:type" content="article">
<meta property="og:title" content="Flutter蓝盾构建指南">
<meta property="og:url" content="https://blog.brzhang.club/2022/12/07/flutter%E8%93%9D%E7%9B%BE%E6%9E%84%E5%BB%BA%E6%8C%87%E5%8D%97/index.html">
<meta property="og:site_name" content="心随我动">
<meta property="og:description" content="众所周知，flutter是比较流行的跨平台方案，目前可以构建出Android，iOS，macOS，Windows，web等产物，这里只想介绍一下Android和iOS的构建产物方式，理解了这两种产物的构建，自动动手实现其他产物，应该并不是什么难事。  首先，要构建出release包，也就是用户可以安装的包，无论是在Android，还是iOS上，都是需要”证书“来签名的。两个平台对比了解如下：">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://blog.brzhang.club/2022/12/07/flutter%E8%93%9D%E7%9B%BE%E6%9E%84%E5%BB%BA%E6%8C%87%E5%8D%97/image-20221207190937458.png">
<meta property="og:image" content="https://blog.brzhang.club/2022/12/07/flutter%E8%93%9D%E7%9B%BE%E6%9E%84%E5%BB%BA%E6%8C%87%E5%8D%97/image-20221207191509340.png">
<meta property="og:image" content="https://blog.brzhang.club/2022/12/07/flutter%E8%93%9D%E7%9B%BE%E6%9E%84%E5%BB%BA%E6%8C%87%E5%8D%97/image-20221207192201361-0412125.png">
<meta property="og:image" content="https://blog.brzhang.club/2022/12/07/flutter%E8%93%9D%E7%9B%BE%E6%9E%84%E5%BB%BA%E6%8C%87%E5%8D%97/image-20221207200414439.png">
<meta property="og:image" content="https://blog.brzhang.club/2022/12/07/flutter%E8%93%9D%E7%9B%BE%E6%9E%84%E5%BB%BA%E6%8C%87%E5%8D%97/image-20221207200948090.png">
<meta property="article:published_time" content="2022-12-07T10:55:14.000Z">
<meta property="article:modified_time" content="2023-11-09T13:06:24.848Z">
<meta property="article:author" content="hz">
<meta property="article:tag" content="Flutter">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://blog.brzhang.club/2022/12/07/flutter%E8%93%9D%E7%9B%BE%E6%9E%84%E5%BB%BA%E6%8C%87%E5%8D%97/image-20221207190937458.png">
  
  
    <meta name="referrer" content="no-referrer-when-downgrade">
  
  
  <title>Flutter蓝盾构建指南 - 心随我动</title><meta name="robots" content="noindex">

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"blog.brzhang.club","root":"/","version":"1.9.5","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"left","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":{"measurement_id":null},"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml","include_content_in_search":true};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.3.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 30vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>Brzhang</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                <span>标签</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                <span>关于</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="Flutter蓝盾构建指南"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        hz
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2022-12-07 18:55" pubdate>
          2022年12月7日 晚上
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          4.2k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          36 分钟
        
      </span>
    

    
    
      
        <span id="busuanzi_container_page_pv" style="display: none">
          <i class="iconfont icon-eye" aria-hidden="true"></i>
          <span id="busuanzi_value_page_pv"></span> 次
        </span>
        
      
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="padding-left: 2rem; margin-right: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <h1 id="seo-header">Flutter蓝盾构建指南</h1>
            
            
              <div class="markdown-body">
                
                <blockquote>
<p>众所周知，flutter是比较流行的跨平台方案，目前可以构建出Android，iOS，macOS，Windows，web等产物，这里只想介绍一下Android和iOS的构建产物方式，理解了这两种产物的构建，自动动手实现其他产物，应该并不是什么难事。</p>
</blockquote>
<p>首先，要构建出release包，也就是用户可以安装的包，无论是在Android，还是iOS上，都是需要”<strong>证书</strong>“来签名的。两个平台对比了解如下：</p>
<table>
<thead>
<tr>
<th>平台</th>
<th>证书</th>
<th>最直接的生成方式</th>
</tr>
</thead>
<tbody><tr>
<td>Android</td>
<td>.jks</td>
<td><a target="_blank" rel="noopener" href="https://www.jianshu.com/p/b9b4b3461ae7">keytool</a>，免费的，谁都可以任意申请</td>
</tr>
<tr>
<td>iOS</td>
<td>.p12 &amp; .mobileprovision</td>
<td>只能去苹果开发者官网申请，or公司有提供的话，比如<a target="_blank" rel="noopener" href="https://keystore.woa.com/dashboard">keystore</a> 申请，本质上都是苹果开发者中心申请，一句话，要钱的</td>
</tr>
</tbody></table>
<p>说个题外话，为啥要签名，一句话，证明这个产物是你生成的。</p>
<p>为了不花多少代价，这里，iOS我们在keystore上申请证书，申请的过程比较简单，其步骤不懂可以找keystore助手，但我们最终需要拿到下图这些证书，尤其是发布环境。因为flutter 构建需要。</p>
<p><img src="/2022/12/07/flutter%E8%93%9D%E7%9B%BE%E6%9E%84%E5%BB%BA%E6%8C%87%E5%8D%97/image-20221207190937458.png" srcset="/img/loading.gif" lazyload alt="image-20221207190937458" loading="lazy" data-src="/2022/12/07/flutter%E8%93%9D%E7%9B%BE%E6%9E%84%E5%BB%BA%E6%8C%87%E5%8D%97/image-20221207190937458.png"></p>
<h4 id="iOS配置篇"><a href="#iOS配置篇" class="headerlink" title="iOS配置篇"></a>iOS配置篇</h4><p>在证书申请成功的前提下，我们需要对iOS工程进行一定的配置，首先，需要下载发布环境的<strong>签名证书</strong>和<strong>描述文件</strong>，然后双击添加到系统keychain里面，相信我过程很简单。然后接下来就是需要对iOS工程进行一定的配置了，使用xcode打开iOS目录。按照红框从左到右的顺序，就可以进入<strong>描述文件</strong>配置的界面，记住，<strong>因为我们是使用公司的证书，而不是自己登录的accont来获取描述文件，因此，我们一定要记住把Automatically mange signing 给反勾选掉</strong>。</p>
<p><img src="/2022/12/07/flutter%E8%93%9D%E7%9B%BE%E6%9E%84%E5%BB%BA%E6%8C%87%E5%8D%97/image-20221207191509340.png" srcset="/img/loading.gif" lazyload alt="image-20221207191509340" loading="lazy" data-src="/2022/12/07/flutter%E8%93%9D%E7%9B%BE%E6%9E%84%E5%BB%BA%E6%8C%87%E5%8D%97/image-20221207191509340.png"></p>
<p>很简单，配置其实就已经OK了，但别急着打包，还要补一个文件到ios工程下面，随便命名都可以，这里为了规范，取名为<code>ExportOptions.plist</code></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs shel">cd ios<br>touch ExportOptions.plist<br></code></pre></td></tr></table></figure>

<p>在里面补充内容</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-meta">&lt;?xml version=<span class="hljs-string">&quot;1.0&quot;</span> encoding=<span class="hljs-string">&quot;UTF-8&quot;</span>?&gt;</span><br><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-keyword">plist</span> <span class="hljs-keyword">PUBLIC</span> <span class="hljs-string">&quot;-//Apple//DTD PLIST 1.0//EN&quot;</span> <span class="hljs-string">&quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">plist</span> <span class="hljs-attr">version</span>=<span class="hljs-string">&quot;1.0&quot;</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">dict</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">key</span>&gt;</span>generateAppStoreInformation<span class="hljs-tag">&lt;/<span class="hljs-name">key</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">false</span>/&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">key</span>&gt;</span>manageAppVersionAndBuildNumber<span class="hljs-tag">&lt;/<span class="hljs-name">key</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">true</span>/&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">key</span>&gt;</span>method<span class="hljs-tag">&lt;/<span class="hljs-name">key</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">string</span>&gt;</span>app-store<span class="hljs-tag">&lt;/<span class="hljs-name">string</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">key</span>&gt;</span>provisioningProfiles<span class="hljs-tag">&lt;/<span class="hljs-name">key</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">dict</span>&gt;</span><br>		<span class="hljs-tag">&lt;<span class="hljs-name">key</span>&gt;</span>com.xxx.xxx<span class="hljs-tag">&lt;/<span class="hljs-name">key</span>&gt;</span><br>		<span class="hljs-tag">&lt;<span class="hljs-name">string</span>&gt;</span>com.xxx.xxx_Production_SignProvision<span class="hljs-tag">&lt;/<span class="hljs-name">string</span>&gt;</span><br>	<span class="hljs-tag">&lt;/<span class="hljs-name">dict</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">key</span>&gt;</span>signingCertificate<span class="hljs-tag">&lt;/<span class="hljs-name">key</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">string</span>&gt;</span>Apple Distribution<span class="hljs-tag">&lt;/<span class="hljs-name">string</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">key</span>&gt;</span>signingStyle<span class="hljs-tag">&lt;/<span class="hljs-name">key</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">string</span>&gt;</span>manual<span class="hljs-tag">&lt;/<span class="hljs-name">string</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">key</span>&gt;</span>stripSwiftSymbols<span class="hljs-tag">&lt;/<span class="hljs-name">key</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">true</span>/&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">key</span>&gt;</span>uploadSymbols<span class="hljs-tag">&lt;/<span class="hljs-name">key</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">false</span>/&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">dict</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">plist</span>&gt;</span><br><br></code></pre></td></tr></table></figure>

<p>别忘记把里面的xxx调换为你自己的BundleID，这个很重要，搞错肯定是打不出包的。好了，接下来验证一下。</p>
<p><strong>在flutter工程根目录下执行：</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">flutter build ipa --export-options-plist $PWD/ios/ExportOptions.plist<br></code></pre></td></tr></table></figure>

<p>不出意外，应该是可以看到</p>
<p><img src="/2022/12/07/flutter%E8%93%9D%E7%9B%BE%E6%9E%84%E5%BB%BA%E6%8C%87%E5%8D%97/image-20221207192201361-0412125.png" srcset="/img/loading.gif" lazyload alt="image-20221207192201361" loading="lazy" data-src="/2022/12/07/flutter%E8%93%9D%E7%9B%BE%E6%9E%84%E5%BB%BA%E6%8C%87%E5%8D%97/image-20221207192201361-0412125.png"></p>
<p>本地的准备工作也就基本上告一段落了，接下来就是去蓝盾上整流水线了。</p>
<p><img src="/2022/12/07/flutter%E8%93%9D%E7%9B%BE%E6%9E%84%E5%BB%BA%E6%8C%87%E5%8D%97/image-20221207200414439.png" srcset="/img/loading.gif" lazyload loading="lazy" data-src="/2022/12/07/flutter%E8%93%9D%E7%9B%BE%E6%9E%84%E5%BB%BA%E6%8C%87%E5%8D%97/image-20221207200414439.png"></p>
<p>流水线步骤比较清晰，第一个是选macOS环境，我这里选择的最新的系统，xcode14.0.1</p>
<p><img src="/2022/12/07/flutter%E8%93%9D%E7%9B%BE%E6%9E%84%E5%BB%BA%E6%8C%87%E5%8D%97/image-20221207200948090.png" srcset="/img/loading.gif" lazyload alt="image-20221207200948090" loading="lazy" data-src="/2022/12/07/flutter%E8%93%9D%E7%9B%BE%E6%9E%84%E5%BB%BA%E6%8C%87%E5%8D%97/image-20221207200948090.png"></p>
<p>git拉取就不必多说，原理就是把项目git clone 到工作空间下；</p>
<p>打包产物这里就有必要详细聊一下了</p>
<p>1、需要准备flutter环境，这里直接在公司的镜像上托下来，思路是直接装到工作空间下，用这个flutter来跑，避免构建机上版本冲突。脚本内容如下:</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><code class="hljs shell"><br>cd $WORKSPACE<br>ARG_FLUTTER_VERSION=3.3.6<br><span class="hljs-meta prompt_"># </span><span class="language-bash">这里就是git拉取代码保存flutter代码的目录，随便写</span><br>BUILD_ROOT=code/<br>echo &quot;执行清理缓存&quot;<br>rm -rf flutter<br>rm -rf /tmp/flutter_output_path.log<br>FLUTTER_DOWNLOAD_URL=&quot;https://mirrors.tencent.com/flutter/flutter_infra_release/releases/stable/macos/flutter_macos_$&#123;ARG_FLUTTER_VERSION&#125;-stable.zip&quot;<br>wget $&#123;FLUTTER_DOWNLOAD_URL&#125; --no-check-certificate -O flutter.zip<br>unzip flutter.zip<br>export PATH=&quot;$(pwd)/flutter/bin:$PATH&quot;<br>echo $PATH<br>FLUTTER_PATH=&quot;$(pwd)/flutter/&quot;<br>export PUB_HOSTED_URL=https://pub.flutter-io.cn<br>export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn<br>echo &quot;PUB_HOSTED_URL=$PUB_HOSTED_URL&quot;<br>echo &quot;FLUTTER_STORAGE_BASE_URL=$FLUTTER_STORAGE_BASE_URL&quot;<br>export PUB_CACHE=~/.pub-cache/<br>rm -rf ~/.pub-cache/*<br>rm -rf $FLUTTER_PATH/.pub-cache/*<br><span class="hljs-meta prompt_"># </span><span class="language-bash">进入flutter项目根目录</span><br>cd $BUILD_ROOT<br>flutter packages get<br><span class="hljs-meta prompt_"># </span><span class="language-bash">执行本地尝试成功的那个构建产物命令</span><br>flutter build ipa --export-options-plist ./ios/ExportOptions.plist<br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_"># </span><span class="language-bash">构建Android产物</span><br>flutter build apk<br><br><br></code></pre></td></tr></table></figure>



<p>可以看到我们大部分工作在准备和本地一致的环境，就是为了执行 <code>flutter build ipa --export-options-plist ./ios/ExportOptions.plist</code>。</p>
<p>2、然后就是开始构建 ipa了。</p>
<p>3、ipa构建好之后，将产物归档，是为了扫二维码可以安装，但我们不安装这个。</p>
<p>4、使用企业微信重新签名。</p>
<p>保存！执行起来，不出意外，可以看到构建产物中有两个ipa了，一个是使用企业证书签名过的，是可以直接在蓝盾上安装了。</p>
<h4 id="Android配置篇"><a href="#Android配置篇" class="headerlink" title="Android配置篇"></a>Android配置篇</h4><p>Android的实现过程其实比较类似，深圳还更加简单些，直接使用keystore上蓝盾的证书，<strong>思路是flutter构建出一个不签名的包</strong>。</p>
<p>然后使用蓝盾插件签名。</p>
<p>因此，我们对android下面的app目录下的build.gradle进行更改，直接把buildTypes配置成这样</p>
<figure class="highlight groovy"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs groovy">buildTypes &#123;<br>       release &#123;<br>           signingConfig <span class="hljs-literal">null</span><br>       &#125;<br>   &#125;<br></code></pre></td></tr></table></figure>

<p>本地执行 ，默认注意需要jdk8</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">flutter build apk<br></code></pre></td></tr></table></figure>

<p>可以看到apk可以构建成功，只不过是一个未签名的，然后由蓝盾上的签名流程的处理就好了，简单的办法是，直接在构建产物环节增加一下 Android产物的构建，过程复用，免得重新搞一个shell，又得安装一下flutter环境等。</p>
<p>至此，整个蓝盾构建flutter工程的Android和ios包均完毕。如果比较幸运，是可以看到产物的。</p>
<pre><code class=" mermaid">graph LR
    A[输入数组] --&gt; B[选择基准元素]
    B --&gt; C[划分数组]
    C --&gt; D[左侧子数组]
    C --&gt; E[右侧子数组]
    D --&gt; F[选择基准元素]
    E --&gt; F
    F --&gt; G[划分数组]
    G --&gt; H[左侧子数组]
    G --&gt; I[右侧子数组]
    H --&gt; J[选择基准元素]
    I --&gt; J
    J --&gt; K[划分数组]
    K --&gt; L[左侧子数组]
    K --&gt; M[右侧子数组]
    L --&gt; N[选择基准元素]
    M --&gt; N
    N --&gt; O[划分数组]
    O --&gt; P[左侧子数组]
    O --&gt; Q[右侧子数组]
    P --&gt; R[选择基准元素]
    Q --&gt; R
    R --&gt; S[划分数组]
    S --&gt; T[左侧子数组]
    S --&gt; U[右侧子数组]
    T --&gt; V[选择基准元素]
    U --&gt; V
    V --&gt; W[划分数组]
    W --&gt; X[左侧子数组]
    W --&gt; Y[右侧子数组]
    X --&gt; Z[选择基准元素]
    Y --&gt; Z
    Z --&gt; AA[划分数组]
    AA --&gt; AB[左侧子数组]
    AA --&gt; AC[右侧子数组]
    AB --&gt; B
    AC --&gt; B
</code></pre>

<!-- flag of hidden posts -->
                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E6%8A%80%E6%9C%AF/" class="category-chain-item">技术</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/Flutter/" class="print-no-link">#Flutter</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>Flutter蓝盾构建指南</div>
      <div>https://blog.brzhang.club/2022/12/07/flutter蓝盾构建指南/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>hz</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2022年12月7日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a class="print-no-link" target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                  </article>
                </div>
              
            </div>

            
  
  
    <article id="comments" lazyload>
      
  <script type="text/javascript">
    Fluid.utils.loadComments('#comments', function() {
      var light = 'github-light';
      var dark = 'github-dark';
      var schema = document.documentElement.getAttribute('data-user-color-scheme');
      if (schema === 'dark') {
        schema = dark;
      } else {
        schema = light;
      }
      window.UtterancesThemeLight = light;
      window.UtterancesThemeDark = dark;
      var s = document.createElement('script');
      s.setAttribute('src', 'https://utteranc.es/client.js');
      s.setAttribute('repo', 'bravekingzhang/bravekingzhang.github.io');
      s.setAttribute('issue-term', 'pathname');
      
      s.setAttribute('label', 'utterances');
      
      s.setAttribute('theme', schema);
      s.setAttribute('crossorigin', 'anonymous');
      document.getElementById('comments').appendChild(s);
    })
  </script>
  <noscript>Please enable JavaScript to view the comments</noscript>


    </article>
  


          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>
  </div>
</div>





  



  



  



  



  


  
  





  <script>
  Fluid.utils.createScript('https://lib.baomitu.com/mermaid/8.14.0/mermaid.min.js', function() {
    mermaid.initialize({"theme":"default"});

    Fluid.utils.listenDOMLoaded(function() {
      Fluid.events.registerRefreshCallback(function() {
        if ('mermaid' in window) {
          mermaid.init();
        }
      });
    });
  });
</script>






    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
    <div class="statistics">
  
  

  
    
      <span id="busuanzi_container_site_pv" style="display: none">
        总访问量 
        <span id="busuanzi_value_site_pv"></span>
         次
      </span>
    
    
      <span id="busuanzi_container_site_uv" style="display: none">
        总访客数 
        <span id="busuanzi_value_site_uv"></span>
         人
      </span>
    
    
  
</div>

  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.4/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.20.1/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  
      <script>
        if (!window.MathJax) {
          window.MathJax = {
            tex    : {
              inlineMath: { '[+]': [['$', '$']] }
            },
            loader : {
              load: ['ui/lazy']
            },
            options: {
              renderActions: {
                insertedScript: [200, () => {
                  document.querySelectorAll('mjx-container').forEach(node => {
                    let target = node.parentNode;
                    if (target.nodeName.toLowerCase() === 'li') {
                      target.parentNode.classList.add('has-jax');
                    }
                  });
                }, '', false]
              }
            }
          };
        } else {
          MathJax.startup.document.state(0);
          MathJax.texReset();
          MathJax.typeset();
          MathJax.typesetPromise();
        }

        Fluid.events.registerRefreshCallback(function() {
          if ('MathJax' in window && MathJax.startup.document && typeof MathJax.startup.document.state === 'function') {
            MathJax.startup.document.state(0);
            MathJax.texReset();
            MathJax.typeset();
            MathJax.typesetPromise();
          }
        });
      </script>
    

  <script  src="https://lib.baomitu.com/mathjax/3.2.2/es5/tex-mml-chtml.js" ></script>

  <script  src="/js/local-search.js" ></script>

  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
